//销售线索

const router = require('koa-router')()
const { duishou } = require('../model')

// 添加数据
router.post('/duishou/add', async (ctx, next) => {
  const { name,customerName,state,nums,tel, establishTime,updateTime} = ctx.request.body
  const res = await duishou.create({ name,customerName,state,nums,tel, establishTime,updateTime})
  if (res) {
    ctx.body = {
      code: 200,
      msg: '添加成功',
      name,customerName,state,nums,tel, establishTime,updateTime
    }
  }
})

// 获取全部数据
router.post('/duishou/getAll', async (ctx, next) => {
  const res = await duishou.find();
  console.log(res);
  if (res) {
    ctx.body = {
      code: 200,
      msg: '获取全部数据成功',
      data: res
    }
  }
})

// 修改数据
router.post('/duishou/update', async (ctx, next) => {
  const {ids,name,customerName,state,nums,tel, establishTime,updateTime} = ctx.request.body
  let res = await duishou.updateOne(
    { _id: ids },
    {name,customerName,state,nums,tel, establishTime,updateTime} 
  )
  if (res) {
    ctx.body = {
      code: 200,
      msg: '修改成功',
      data: res,
      department,
    }
  }
})

module.exports = router